<?php
    apf_require_class("PageHelper");
    $img_path = '/img/home/';
    ?>

<div class="header">
    <div class="bg_top"></div>
    <div class="logo"></div>
</div>
<div class="container">
    <?php $menu_list = array(
            array('act'=>'list','url'=>Flow_Urls::flow_list(),'name'=>'需处理'),
            array('act'=>'process','url'=>Flow_Urls::flow_done_list(),'name'=>'已处理'),
            );
        if($data['t_role']){
            $menu_list[] = array('act'=>'all','url'=>Flow_Urls::flow_all_list(),'name'=>'流程监控');
        }
    ?>
    <div class="topic">
        <span class="a1">&nbsp;</span><?php foreach($menu_list as $k=>$val):?>
<?php
$class = $k==0 ? 'uneed1':'uneed';
if($params['do']==$val['act']){
$class = 'need';
}
?><a href="<?=$val['url']?>" class="<?=$class?>"><?=$val['name']?></a><?php endforeach;?><span class="a<?=count($menu_list)?>"><?php if($is_hr_admin):?><a href="<?=Flow_Urls::flow_role()?>" target="_blank" style="color: #0000fd;">角色设置</a><i></i><?php else:?>&nbsp;<?php endif;?><?php if( isset($role_list[Const_Flow::ROLE_IT]) && $data['datalist'] && $params['do']=='list'):?><a href="javascript:output();" style="color: #0000fd;">批量导出</a><?php else:?>&nbsp;<?php endif;?></span></div>
    <form id="form1" action="#" method="post" style="width: 837px;">
        <div class="h">
            <span>
            <select class="select" name="city_id">
            <option value="0">城市</option>
            <?php foreach($data['citylist'] as $val):?>
            <option value="<?=$val['city_id']?>" <?php if($val['city_id']==$params['city_id']):?>selected<?php endif;?>><?=$val['city_name']?></option>
            <?php endforeach;?></select>
            </span>
            <span>
            <select class="select" name="flow_type">
            <option value="0">流程类型</option>
            <?php foreach($data['flow_type_list'] as $k=> $val):?>
            <option value="<?=$k?>" <?php if($k==$params['flow_type']):?>selected<?php endif;?>><?=$val?></option>
            <?php endforeach;?>
            </select></span>
            <?php if($params['do']=='process'):?>
            <span><input type="text" placeholder="姓名" class="select" name="user_name" value="<?=$params['user_name']?>"></span>
            <?php endif;?>
            <?php if($params['do']=='all' && !empty($data['t_role'])):?>
            <select class="select" name="now_status">
            <option value="0">流程阶段</option>
            <option value="1" <?php if($params['now_status']==1):?>selected<?php endif;?>>正在进行</option>
            <option value="2" <?php if($params['now_status']==2):?>selected<?php endif;?>>已完成</option>
            <option value="3" <?php if($params['now_status']==3):?>selected<?php endif;?>>已撤消</option>
            <option value="4" <?php if($params['now_status']==4):?>selected<?php endif;?>>系统处理</option>
            </select>
            <?php endif;?>
            <span><input type="text" class="time date" id="entry_date" name="start" value="<?=$params['start']?>"></span><span>至</span>
            <span><input type="text" class="time date" id="entry_date_1" name="end" value="<?=$params['end']?>"></span>
            <span><input type="submit" value="查询" class="button"></span>
        </div>
    </form>
    <form id="multi_form" action="#" method="post" >
        <table class="table" cellpadding="0" cellspacing="0" border="0" style="border-collapse:collapse">
            <thead class="t">
                <tr>
                    <th class="t1"><input type="checkbox" id="chk_all"/></th>
                    <th class="t2">生效时间</th>
                    <th class="t3">流程类型</th>
                    <th class="t4">姓名</th>
                    <th class="t4">工作城市</th>
                    <th class="t3">部门-职位</th>
                    <th class="t3">流程阶段</th>
                    <th class="t1">操作</th>
                </tr>
            </thead>
            <tbody class="tb">
            <?php if($data['datalist']):?>
            <?php foreach($data['datalist'] as $val):?>
            <?php $is_bold = ($val['recruit'] && $params['do']=='all' && !empty($data['t_role'][Const_Flow::ROLE_RECRUIT])) ? 'style="font-weight:700"' : '';?>
                <tr>
                    <td class="t1"><input type="checkbox" name="flow_ids[]" value="<?=$val['flow_id']?>"></td>
                    <td class="t2" <?=$is_bold?>><?=date('Y-m-d',strtotime($val['effect_date']))?></td>
                    <td class="t3" <?=$is_bold?>>
                    <?php
                    $flow_type =$val['flow_type'];
                    if($val['flow_type']==Const_Flow::FLOW_TYPE_TRANSFER || $val['flow_type']==Const_Flow::FLOW_TYPE_MONEY){
                        $flow_type = Const_Flow::FLOW_TYPE_TRANSFER;
                    }
                    $txt= $data['flow_type_list'][$flow_type];
                    if($userinfo_list[$val['flow_id']]['is_entry']==2){//hr取消入职的,it和行政查看
                    $txt.='(取消)';
                    }
                    echo $txt;
                    ?></td>
                    <td class="t4" <?=$is_bold?>><?=$userinfo_list[$val['flow_id']]['name']?> <?=$userinfo_list[$val['flow_id']]['code']?></td>
                    <td class="t4" <?=$is_bold?>><?=$userinfo_list[$val['flow_id']]['city_name']?></td>
                    <td class="t3" <?=$is_bold?>><?=$userinfo_list[$val['flow_id']]['department_name']?><br><?=$userinfo_list[$val['flow_id']]['job_name']?></td>
                    <td class="t3" <?=$is_bold?>>

                    <?php $deurl=$val['url']; if($val['now_status']==2):?>
                    已完成
                    <?php elseif($val['now_status']==3):?>
                    已撤消
                    <?php elseif($val['now_status']==4):?>
                    系统处理
                    <?php else:?>
                    <?=$val['role_list']?>
                    <?php endif;?>
                    </td>

                    <td class="t1"><a href="<?=$deurl?>" target="_blank"><?php if($params['do']=='list'):?>办理<?php else:?>查看<?php endif;?></a></td>
                </tr>
            <?php endforeach;?>
            <?php endif;?>
            </tbody>
            <!--<tfoot class="tf">
                <tr>
                    <td><span class="btn">确认入职</span></td>
                    <td><span class="btn">取消入职</span></td>
                    <td><span class="btn1"></span></td>
                    <td><span class="btn" style="color:#666666">批量处理</span></td>
                </tr>
            </tfoot>-->
        </table>

<div style="float: left;margin-left: 20px;margin-top: 10px;">
<?php if($params['do']=='list' && $params['flow_type']==Const_Flow::FLOW_TYPE_ENTRY && $data['datalist']){?>
<input type="hidden" name="type" class="form_type" />
<?php if(isset($role_list[Const_Flow::ROLE_HR])){?>
<input type="button" class="btn" id="btnEntry" style="color:#666666;border: none" value="确认入职"/>
<input type="button" class="btn" id="btnCancelEntry" style="color:#666666;border: none" value="取消入职"/>
<?php }?>
<?php if(isset($role_list[Const_Flow::ROLE_ADMIN]) || isset($role_list[Const_Flow::ROLE_IT])){?>
<input type="button" class="btn" id="btnBatchDeal" style="color:#666666;border: none" value="批量办理"/>
<?php }}?>
<?php if(($params['do']=='process'||$params['do']=='all') && isset($role_list[Const_Flow::ROLE_HR]) && $data['datalist']){?>
<span class="btn1" id="btnMulitPrint">&nbsp;</span>
<?php }?>
</div>
    </form>

    <div class="footer">
    <?php if(isset($data['multipage']) && !empty($data['multipage']['list'])) {?>
        <?php $this->component('Flow_MultiPage', array('multipage'=>$data['multipage'])); ?>
        <?php } ?>
    </div>
</div>



<?php $this->script_block_begin(); ?>
<script type="text/javascript">
var url_user = "<?php echo Portal_Urls::ajax_search_user();?>";
var urlForm = "<?php echo Flow_Urls::flow_dolist();?>";
var url_print="<?=Flow_Urls::build_multi_print()?>";
var output_url = "<?=Flow_Urls::flow_output()?>";
function output(){
    var $start = $('#entry_date').val();
    var $end = $('#entry_date_1').val();
    if($start == "" && $end != ""){
        $('#entry_date').focus();
        return;
    }
    if($end == "" && $start != ""){
        $('#entry_date_1').focus();
        return;
    }
    if($end != "" && $start != ""){
        if(comptime($start,$end)){
            document.location.href=output_url+"?start="+$start+"&end="+$end;;
        }else{
            $('#entry_date_1').val("");
            $('#entry_date_1').focus();
        }
    }else{
        document.location.href=output_url;
    }
}
function comptime(startDate,endDate) {
    startDate = startDate+" 00:00:00";
    endDate =endDate+" 00:00:00";
    if (startDate.length > 0 && endDate.length > 0) {
       var startDateTemp = startDate.split(" ");
       var endDateTemp = endDate.split(" ");

       var arrStartDate = startDateTemp[0].split("-");
       var arrEndDate = endDateTemp[0].split("-");

       var arrStartTime = startDateTemp[1].split(":");
       var arrEndTime = endDateTemp[1].split(":");

       var allStartDate = new Date(arrStartDate[0], parseInt(arrStartDate[1])-1, arrStartDate[2], arrStartTime[0], arrStartTime[1], arrStartTime[2]);
       var allEndDate = new Date(arrEndDate[0], parseInt(arrEndDate[1])-1, arrEndDate[2], arrEndTime[0], arrEndTime[1], arrEndTime[2]);

       if (allStartDate.getTime() > allEndDate.getTime()) {
          alert("结束时间不能小于开始时间");
          return false;
       } else {
          return true;
       }
   } else {
         return false;
   }
}
</script>


<?php $this->script_block_end(); ?>